package Classic150;

public class 买卖股票的最佳时机2 {
    /*
        贪心，折线上升就加上
     */
    public int maxProfit(int[] prices) {
        /*int min = Integer.MAX_VALUE;
        int maxProfit = 0;
        for (int price : prices) {
            if (min < price) maxProfit += price - min;
            min = price;
        }
        return maxProfit;*/

        int profit = 0;
        for (int i = 1; i < prices.length; i++) {
            if (prices[i] - prices[i - 1] > 0) profit = profit + prices[i] - prices[i - 1];
        }
        return profit;
    }
}
